package com.yanqu.road.server.manger.bug;

import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.logic.bussiness.player.UserBussiness;
import com.yanqu.road.logic.thread.ThreadTaskManger;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.timer.banquet.BanquetSyncMemberTask;
import com.yanqu.road.server.timer.bug.BugTask;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.math.BigInteger;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 修bug专用mgr
 */
public class BugMgr extends TempMgr {

    protected Logger logger = LogManager.getLogger(BugMgr.class.getName());

    private static ThreadTaskManger threadTaskManger;

    private static AtomicInteger taskId = new AtomicInteger(1);

    private static Map<Long, UserInfo> bugUserInfoMap;

    //跨服赚速没有更新？？？
    private void bug(){
        bugUserInfoMap = UserBussiness.getUserInfoMap();
        for (UserInfo userInfo : bugUserInfoMap.values()){
            if (userInfo.getEarnSpeed().compareTo(BigInteger.valueOf(50000l)) >= 0 || !StringUtils.isNullOrEmpty(userInfo.getUnionUid())) {
                if (threadTaskManger != null) {
                    threadTaskManger.addTask(taskId.getAndIncrement(),new BugTask(userInfo));
                }
            }
        }
    }


    @Override
    public boolean init() {
        return reload();
    }


    public boolean save() {
        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }

    @Override
    public boolean reload() {
        if(System.currentTimeMillis() <= 1598025600000l){
            if (threadTaskManger == null) {
                threadTaskManger = new ThreadTaskManger(10, "BugTaskManger");
            }
            bug();
        }

        return true;
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

}
